package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.SingleQuotesArg;
import com.azier.kapacitor.script.method.*;
import com.azier.kapacitor.script.node.nodebind.CommonNodeBind;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
The query to execute. Must not contain a time condition in the WHERE clause or contain a GROUP BY clause. The time conditions are added dynamically according to the period, offset and schedule. The GROUP BY clause is added dynamically according to the dimensions passed to the groupBy method.
**/
/**
要执行的查询。不能在WHERE子句中包含时间条件，也不能包含GROUP BY子句。时间条件会根据时间段，偏移量和时间表动态添加。 GROUP BY子句是根据传递给groupBy方法的尺寸动态添加的。
**/
public class QueryNode extends AbstractNode implements CommonNodeBind {
    private static final String name = "query";

    public QueryNode(String q) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        this.args.add(new SingleQuotesArg(q));
    }

    /**
    Align start and stop times for queries with even boundaries of the QueryNode.Every property. Does not apply if using the QueryNode.Cron property.
    **/
    /**
    使查询的开始和停止时间与QueryNode.Every属性的边界相等。如果使用QueryNode.Cron属性，则不适用。
    **/
    public QueryNode align(){
        Align align = new Align();
        super.addMethod(align);
        return this;
    }
    /**
    Align the group by time intervals with the start time of the query
    **/
    /**
    按时间间隔将组与查询的开始时间对齐
    **/
    public QueryNode alignGroup(){
        AlignGroup alignGroup = new AlignGroup();
        super.addMethod(alignGroup);
        return this;
    }
    /**
    The name of a configured InfluxDB cluster. If empty the default cluster will be used.
    **/
    /**
    已配置的InfluxDB集群的名称。如果为空，将使用默认群集。
    **/
    public QueryNode cluster(String query){
        Cluster cluster = new Cluster(query);
        super.addMethod(cluster);
        return this;
    }
    /**
    Define a schedule using a cron syntax.
    **/
    /**
    使用cron语法定义时间表。
    **/
    public QueryNode cron(String query){
        Cron cron = new Cron(query);
        super.addMethod(cron);
        return this;
    }
    /**
    How often to query InfluxDB.
    **/
    /**
    查询InfluxDB的频率。
    **/
    public QueryNode every(long interval, String durationLiteral){
        Every every = new Every(interval, durationLiteral);
        super.addMethod(every);
        return this;
    }
    /**
    Fill the data. Options are:
    **/
    /**
    填写数据。选项有：
    **/
    public QueryNode fill(Object query){
        Fill fill = new Fill(query);
        super.addMethod(fill);
        return this;
    }
    /**
    Group the data by a set of dimensions. Can specify one time dimension.
    **/
    /**
    按一组维度对数据进行分组。可以指定一个时间维度。
    **/
    public QueryNode groupByM(Object ...d){
        GroupBy groupBy = new GroupBy(d);
        super.addMethod(groupBy);
        return this;
    }
    /**
    If set will include the measurement name in the group ID. Along with any other group by dimensions.
    **/
    /**
    如果设置，则将测量名称包含在组ID中。连同其他按维度分组。
    **/
    public QueryNode groupByMeasurement(){
        GroupByMeasurement groupByMeasurement = new GroupByMeasurement();
        super.addMethod(groupByMeasurement);
        return this;
    }
    /**
    How far back in time to query from the current time
    **/
    /**
    距当前时间多远的时间查询
    **/
    public QueryNode offset(long interval, String durationLiteral){
        Offset offset = new Offset(interval, durationLiteral);
        super.addMethod(offset);
        return this;
    }
    /**
    The period or length of time that will be queried from InfluxDB
    **/
    /**
    从InfluxDB查询的时间段或时间长度
    **/
    public QueryNode period(long interval, String durationLiteral){
        Period period = new Period(interval, durationLiteral);
        super.addMethod(period);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public QueryNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
}